#include<bits/stdc++.h>
using namespace std;
int d[100005], v[100005], a[100005];
int h[100005];
vector<int>g[100005];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin >> T;
    for(int i = 1; i <= T; i++)
    {
        int n, m, L, V;
        cin >> n >> m >> L >> V;
        int maxm = -1;
        for(int j = 1;j <= n; j++)
        {
            scanf("%d%d%d",&d[j], &v[j], & a[j]);
        }
        for(int j = 1;j <= m; j++)
        {
            int x;
            cin >> x;
            maxm = max(maxm, x);
        }
        int ans = 0;
        for(int j = 1; j <= n; j++)
        {
            if(d[j] <= maxm && v[j] > V)ans++;
        }

        if(ans == 0)cout <<ans << " " << m << endl;
        else cout << ans << " " << m - 1 << endl;
    }
    return 0;
}
